home *** CD-ROM | disk | FTP | other *** search
- $If 0
-
- ╔═══════════════════════════════════════════════╤═══════════════╗
- ║ Program : Simpsons Rule (Evaluate an integral)│ Version : 0.0 ║
- ╟────────────────────────────────┬──────────────┴───────────────╢
- ║ Written by Kurt J. Wolf │ [X] Released to public ║
- ║ Copyright 1994 by Kurt J. Wolf │ [ ] Do not release to public ║
- ╟────────────────────────────────┼──────────────────────────────╢
- ║ Compiler : PowerBASIC │ Compiler Version : 3.0c ║
- ╚════════════════════════════════╧══════════════════════════════╝
- Home : 39 Brentwood Rd School : PSU - MA Box 267
- Camp Hill, PA 17011 Mont Alto, PA 17237
- (717) 763-8913 (717) 749-6430
- InterNet : kjw124@psuvm.psu.edu
-
- ───────────────────────────────────────────────────────< Notes >─
- ---This is another method for evaluating a definit integral. This
- method will not return the same values found using the trapazoid
- rule, they are two different beasts. If you would like to use this
- code, feel free, I don't mind, just drop me a line and tell me that
- you are using it. (More of an ego boost than anything!)
-
- ---Thank you once again, Lloyd.
- $Endif
-
- function f#(x#) public
- f# = x# ^ 2 + 1.0
- end function
-
- function integrand#(a#, b#, n#) public
- h# = (b# - a#) / n#
- h2# = h# / 2
- for i% = 1 to n# - 1
- x# = a# + i% * h#
- sum1# = sum1# + f#(x#)
- sum2# = sum2# + f#(x# + h2#)
- Next i%
- integrand# = h# * (f#(a#) + 2.0 * sum1# + f#(b#) + 4.0 * sum2#) / 6.0
- end function
-
- print str$(integrand#(0, 1, 10))
- print str$(integrand#(0, 1, 20))
- print str$(integrand#(0, 1, 100))